from app import create_app, db
from app.models import User, Service, ServiceCategory, ServiceProvider, Rating, Carousel

def init_db():
    app = create_app()
    with app.app_context():
        # 删除所有表
        db.drop_all()
        
        # 创建所有表
        db.create_all()
        
        # 创建超级管理员用户
        admin = User(
            username='admin',
            email='admin@example.com',
            is_admin=True
        )
        admin.set_password('admin123')
        
        # 创建测试用户
        test_user = User(
            username='test',
            email='test@example.com',
            is_admin=False
        )
        test_user.set_password('test123')
        
        # 创建测试类别
        category = ServiceCategory(
            name='测试类别',
            description='这是一个测试类别'
        )
        
        # 创建测试服务提供者
        provider = ServiceProvider(
            name='测试提供者',
            description='这是一个测试提供者',
            category=category
        )
        
        db.session.add(admin)
        db.session.add(test_user)
        db.session.add(category)
        db.session.add(provider)
        db.session.commit()
        
        print('Database initialized successfully!')
        print('Admin account created:')
        print('Username: admin')
        print('Password: admin123')
        print('Test account created:')
        print('Username: test')
        print('Password: test123')
        print('Test category created with ID:', category.id)
        print('Test provider created with ID:', provider.id)

if __name__ == '__main__':
    init_db() 